/*
 * Copyright (C) 2009 Tom Barber
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
 *
 * @created Apr 23, 2009 
 * @author Tom Barber
 */
package com.encon.projecttracker.client.util.factory;


import com.encon.projecttracker.rpc.Query;
import com.encon.projecttracker.rpc.QueryAsync;
import com.encon.projecttracker.rpc.Session;
import com.encon.projecttracker.rpc.SessionAsync;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.ServiceDefTarget;

/**
 * The Class ServiceFactory.
 * 
 * @author Tom Barber
 */
public class ServiceFactory {

    /** The session service. */
	private static QueryAsync qService = null;
	
	/** The session service. */
	private static SessionAsync sService = null;
	/**
	 * Gets the session instance.
	 * 
	 * @return the session instance
	 */
	public static SessionAsync getSessionInstance() {
		if (sService == null) {
			sService = (SessionAsync) GWT.create(Session.class);
			final ServiceDefTarget endpoint = (ServiceDefTarget) sService;
			final String moduleRelativeURL = GWT.getModuleBaseURL() + "session.rpc"; //$NON-NLS-1$
			endpoint.setServiceEntryPoint(moduleRelativeURL);
		}
		return sService;
	}

	/**
	 * Gets the query instance.
	 * 
	 * @return the session instance
	 */
	public static QueryAsync getQueryInstance() {
		if (qService == null) {
			qService = (QueryAsync) GWT.create(Query.class);
			final ServiceDefTarget endpoint = (ServiceDefTarget) qService;
			final String moduleRelativeURL = GWT.getModuleBaseURL() + "query.rpc"; //$NON-NLS-1$
			endpoint.setServiceEntryPoint(moduleRelativeURL);
		}
		return qService;
	}
}
